﻿@page "/acc-roles"
@using GMS.NET.Dto.System.AccRoles.Shared
@using GMS.NET.Dto.System.AccRoles.Enums
@using GMS.NET.Web.Components.Pages.Systems.AccRoles.Shared
@attribute [TabItemOption(Text = "角色授权")]

<Card IsShadow="true" HeaderText="角色授权">
    <BodyTemplate>
        <Table TItem="RolesData" IsBordered="true" IsStriped="true" IndentSize="8" HeaderStyle="@TableHeaderStyle.Light"
               TreeIcon="fa-solid fa-circle-chevron-right" OnQueryAsync="@OnQueryAsync" ShowToolbar="true" ShowExtendButtons="true" OnSaveAsync="@OnSaveAsync" OnDeleteAsync="@OnDeleteAsync" ShowEditButton="false" EditDialogIsDraggable="true"
               AddModalTitle="新增用户" EditModalTitle="编辑用户" ShowEmpty="true" IsPagination="true" IsMultipleSelect="true"
               PageItemsSource="@(new int[] { 20, 40, 80, 100 })" 
               SearchMode="SearchMode.Top" ShowSearch="true" ShowSearchText="false" CustomerSearchModel="@custsSearchModel"
               @ref="Table">
            <TableColumns>
                <TableColumn @bind-Field="@context.Role_Name" Sortable />
                <TableColumn @bind-Field="@context.Role_CustsName" />
                <TableColumn @bind-Field="@context.Role_Status">
                    <Template Context="value">
                        <Switch Value="@(value.Value==Role_Status.normal)" ValueChanged="(val)=>RolesStatusOnChanged(val,value.Row.Id)"
                                OnColor="Color.Success" OnText="正常" OffText="禁用"></Switch>
                    </Template>
                </TableColumn>
                <TableColumn @bind-Field="@context.Role_Remark" />
            </TableColumns>
            <RowButtonTemplate>
                <TableCellButton Text="分配用户" Icon="fas fa-fw fa-users-gear" Color="Color.Warning" OnClickWithoutRender="()=>RoleAddUsers(context.Id,context.Role_Name)" />
                <TableCellButton Text="分配资源" Icon="fas fa-fw fa-file-shield" Color="Color.Success" OnClickWithoutRender="()=>RoleAddRess(context.Id,context.Role_Name)" />
            </RowButtonTemplate>
            <EditTemplate Context="value">
                <AccRolesForm Context="value" />
            </EditTemplate>
            <CustomerSearchTemplate>
                @if (context is AccRolesSearchModel model)
                {
                    <AccRolesSearch @bind-Value="@model" />
                }
            </CustomerSearchTemplate>
        </Table>
    </BodyTemplate>
</Card>

<Modal @ref="UsersModal">
    <ModalDialog Title="@UserModalTitle" IsCentered="true">
        <BodyTemplate>
            <Table TItem="GMS.NET.Dto.System.AccRoles.Output.WaitUsers" IsStriped="true" @bind-SelectedRows="@SelectedUsers" ClickToSelect="true"
                   ShowToolbar="true" ShowDefaultButtons="false" IsMultipleSelect="true" IsPagination="true"
                   OnQueryAsync="@OnQueryUsersAsync" HeaderStyle="TableHeaderStyle.Light" ShowEmpty="true" @ref="waitUsers">
                <TableColumns>
                    <TableColumn @bind-Field="@context.User_Account" />
                    <TableColumn @bind-Field="@context.User_Name" />
                    <TableColumn @bind-Field="@context.Custs_Name" />
                    <TableColumn @bind-Field="@context.Role_Name" />
                </TableColumns>
            </Table>
        </BodyTemplate>
        <FooterTemplate>
            <Button Text="确定" Icon="fa-regular fa-square-check" OnClick="@RoleAddUsersOnConfirm" />
        </FooterTemplate>
    </ModalDialog>
</Modal>

<Modal @ref="RessModal">
    <ModalDialog Title="@RessModalTitle" IsCentered="true" Size="Size.Medium " >
        <BodyTemplate>
            <TreeView TItem="GMS.NET.Dto.System.AccRoles.Output.WaitRess" Items="@AsyncItems" ShowCheckbox="true" OnTreeItemChecked="@OnTreeItemChecked" ShowSkeleton="true"   ShowIcon="true"/>
        </BodyTemplate>
        <FooterTemplate>
            <Button Text="确定" Icon="fa-regular fa-square-check" OnClick="@RoleAddRessOnConfirm" />
        </FooterTemplate>
    </ModalDialog>
</Modal>